package com.flynn.rock.system.controller;

import com.flynn.rock.model.PageResult;
import com.flynn.rock.model.Response;
import com.flynn.rock.system.model.request.PageUserMessageRequest;
import com.flynn.rock.system.model.vo.MessageCountVo;
import com.flynn.rock.system.model.vo.MessageVo;
import com.flynn.rock.system.service.SysMessageService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/sys/message")
@AllArgsConstructor
@Tag(name = "系统消息管理")
public class SysMessageController {

    private SysMessageService sysMessageService;

    @GetMapping("/user/count")
    @Operation(summary = "获取用户消息数量")
    public Response<MessageCountVo> getUserMessageCount() {
        return Response.success(sysMessageService.getUserMessageCount());
    }

    @PutMapping("/user/read/all")
    public Response<Void> readAllUserMessage() {
        sysMessageService.readAllUserMessage();
        return Response.success(null);
    }

    @PostMapping("/user/page")
    @Operation(summary = "获取用户消息列表")
    public Response<PageResult<MessageVo>> pageUserMessage(@RequestBody PageUserMessageRequest request) {
        return Response.success(sysMessageService.pageUserMessage(request));
    }

    @GetMapping("/detail/{messageId}")
    @Operation(summary = "获取消息详情")
    public Response<MessageVo> getMessageDetail(@PathVariable("messageId") Long messageId) {
        return Response.success(sysMessageService.getMessageDetail(messageId));
    }
}
